use std::cmp::min;

struct Solution {}

impl Solution {
    pub fn longest_palindrome(s: String) -> String {
        for (i, c) in s.char_indices() {}
        String::new()
    }
}

pub fn brute(s: String) -> String {
    for i in 0..s.len() {
        // 左右搜索
        for j in 0..min(i + 1, s.len() - i) {
            for k in 1..j {
                if j - k {}
            }
        }
    }
    String::new()
}

pub fn even_palindrome_at(s: String, pos: usize) -> usize {
    let mut half_len = 0;
    for i in 0..min(pos, s.len() - pos) {
        if s[pos - i] == s[pos + i + 1] { half_len = i + 1 } else { break; }
    }
    half_len * 2
}

pub fn odd_palindrome_at(s: String, pos: usize) -> usize {
    let mut half_len = 0;
    for i in 1..min(pos - 1, s.len() - pos) {
        if s[pos - i] == s[pos + i] { half_len = i + 1 } else { break; }
    }
    half_len * 2 + 1
}

#[cfg(test)]
mod tests {
    use syntax::util::map_in_place::MapInPlace;

    use crate::Solution;

    #[test]
    fn it_works1() {
        let cases = vec![("babad", "bab"), ("cbbd", "bb")];
        for (input, expected) in cases {
            let s1 = String::from(input);
            let s2 = String::from(expected);
            assert_eq!(s2, Solution::longest_palindrome(s1));
        }
    }
}
